package patrol.mobile.com.mobilepatrol.receiver;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
import com.xiaomi.mipush.sdk.MiPushMessage;
import com.xiaomi.mipush.sdk.PushMessageReceiver;

/**
 * Created by z on 2018/9/7.
 * Des:
 */

public class MyMessageReceiver extends PushMessageReceiver {

    //接收服务器发送的透传消息
    @Override
    public void onReceivePassThroughMessage(Context context, MiPushMessage miPushMessage) {
        super.onReceivePassThroughMessage(context, miPushMessage);
        Log.e("透传消息", new Gson().toJson(miPushMessage));
    }

    //接收服务器发来的通知栏消息（用户点击通知栏时触发）
    @Override
    public void onNotificationMessageClicked(Context context, MiPushMessage miPushMessage) {
        super.onNotificationMessageClicked(context, miPushMessage);
        Log.e("通知栏消息", new Gson().toJson(miPushMessage));
    }

    //接收服务器发来的通知栏消息（消息到达客户端时触发，并且可以接收应用在前台时不弹出通知的通知消息）
    @Override
    public void onNotificationMessageArrived(Context context, MiPushMessage miPushMessage) {
        super.onNotificationMessageArrived(context, miPushMessage);
        Log.e("通知栏消息02", new Gson().toJson(miPushMessage));
    }

    //接收客户端向服务器发送命令消息后返回的响应
    @Override
    public void onCommandResult(Context context, MiPushCommandMessage miPushCommandMessage) {
        super.onCommandResult(context, miPushCommandMessage);
        Log.e("返回响应", new Gson().toJson(miPushCommandMessage));
    }

    //接受客户端向服务器发送注册命令消息后返回的响应
    @Override
    public void onReceiveRegisterResult(Context context, MiPushCommandMessage miPushCommandMessage) {
        super.onReceiveRegisterResult(context, miPushCommandMessage);
        Log.e("返回响应02", new Gson().toJson(miPushCommandMessage));
//        MiPushClient.setAlias();注册成功后 可添加设备别买 订阅事件等操作
    }
}
